package org.infodavid.common.persistence;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;

import org.junit.Test;

/**
 * The Class SqlScriptHelperTestManual.
 */
public class SqlScriptHelperTestManual {

  /**
   * Test execute.
   * @throws Exception
   */
  @Test
  public void testExecute() throws Exception {
    InputStream in = null;
    Connection conn = null;

    try {
      in = getClass().getResourceAsStream("/tables_mysql.sql");

      Class.forName("com.mysql.jdbc.Driver");

      final SqlScriptHelper helper = SqlScriptHelper.getInstance();
      conn = DriverManager.getConnection("jdbc:mysql://192.168.0.5/notifier", "notifier", "notifier");

      conn.setAutoCommit(false);
      helper.execute(conn, helper.parse(in));
      conn.commit();
    }
    finally {
      if (in != null) {
        in.close();
      }

      if (conn != null) {
        conn.close();
      }
    }
  }

}
